<html>
<head><meta charset="utf-8"><title>Next steps for my idea regardings callables and coherence · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Next.20steps.20for.20my.20idea.20regardings.20callables.20and.20coherence.html">Next steps for my idea regardings callables and coherence</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="247866017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Next%20steps%20for%20my%20idea%20regardings%20callables%20and%20coherence/near/247866017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Kalbertodt <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Next.20steps.20for.20my.20idea.20regardings.20callables.20and.20coherence.html#247866017">(Aug 01 2021 at 16:20)</a>:</h4>
<p>Hi there! Some time ago, I had this idea: <a href="https://internals.rust-lang.org/t/solving-coherence-problems-with-trait-impls-for-closures-provide-a-closure-wrapper-in-libcore-and-make-closure-expressions-evaluate-to-that-type/11174">https://internals.rust-lang.org/t/solving-coherence-problems-with-trait-impls-for-closures-provide-a-closure-wrapper-in-libcore-and-make-closure-expressions-evaluate-to-that-type/11174</a></p>
<p>It would help with implementing traits for callables (e.g. closures) <em>without</em> having a blanket impl and getting problems with overlapping impls and coherence. All problems that have been brought up can be resolved and some people liked the idea.</p>
<p>So how to proceed from here? I don't know a lot about compiler internals. I'm not even sure if t-lang is the most fitting team for this. Should I just open a pre-RFC thread? Or an RFC immediately? I don't feel I have enough knowledge to write an RFC about this. Is someone interested in this and would like to work on that together with me?</p>



<a name="247945123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Next%20steps%20for%20my%20idea%20regardings%20callables%20and%20coherence/near/247945123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Next.20steps.20for.20my.20idea.20regardings.20callables.20and.20coherence.html#247945123">(Aug 02 2021 at 17:21)</a>:</h4>
<p>The example you mentioned in that thread already compiles (after minor changes) since <code>Fn</code> is <code>#[fundamental]</code></p>



<a name="247977658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Next%20steps%20for%20my%20idea%20regardings%20callables%20and%20coherence/near/247977658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Next.20steps.20for.20my.20idea.20regardings.20callables.20and.20coherence.html#247977658">(Aug 02 2021 at 22:08)</a>:</h4>
<p>Hrm, would this also allow specializing on the distinction between <code>Fn</code> vs <code>FnMut</code> closures?</p>



<a name="248199211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Next%20steps%20for%20my%20idea%20regardings%20callables%20and%20coherence/near/248199211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Next.20steps.20for.20my.20idea.20regardings.20callables.20and.20coherence.html#248199211">(Aug 03 2021 at 09:24)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink  [he/him]</span> <a href="#narrow/stream/213817-t-lang/topic/Next.20steps.20for.20my.20idea.20regardings.20callables.20and.20coherence/near/247945123">said</a>:</p>
<blockquote>
<p>The example you mentioned in that thread already compiles (after minor changes) since <code>Fn</code> is <code>#[fundamental]</code></p>
</blockquote>
<p>I believe the issue was not <em>w.r.t.</em> <code>T : Fn…</code> <em>vs.</em>, say, <code>HashMap</code>, but, rather, with the extra <code>&amp;T where T : Trait</code> transitivity. Since <code>Fn</code> is also <code>&amp;</code>-transitive, that leads to a conflicting impl.</p>
<p>In order to avoid that, the OP wants a way to have some kind of marker on "primitive" closures, and they suggested having those be contained within a wrapper type for that. Another option (not saying it's better, just mentioning it for the sake of completeness) would be to have another set of <code>#[fundamental]</code> traits which would only be implemented for <code>$(move)? |…| …</code> closures, meaning it would not be <code>&amp;</code> /<code>&amp;mut</code> / <code>Box</code>-transitive, thus allowing that kind of impls.</p>
<ul>
<li>Note that whatever it may be, I think it would be a bit weird for users of the API to observe that <code>dyn Fn…</code> would not work. Because of this observation, I believe specialization could be the right tool for this, albeit, granted, not a near future one. Moreover, it involves the currently unsupported challenge of the diamond problem (<code>&amp;(impl Fn + ?Sized)</code> is a subset of <code>&amp;impl ?Sized</code> and of <code>impl Fn</code>, and the latter two sets are not contained within either), about which I've talked in URLO: <a href="https://users.rust-lang.org/t/help-with-min-specialization/56224/3?u=yandros">https://users.rust-lang.org/t/help-with-min-specialization/56224/3?u=yandros</a></li>
</ul>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>